# class Solution:
#     def partitionLabels(self, S: str) -> List[int]:
#         start=ord('a')
#         keys=[chr(start+i) for i in range(26)]
#         freqset=dict(map(lambda x:(x,[-1,-1]),keys))
#         end=0
#         result=[]
#         for i in range(len(S)):
#             if freqset[S[i]][0]==-1:
#                 freqset[S[i]][0]=i
#                 freqset[S[i]][1]=i
#             else:
#                 freqset[S[i]][1]=i
#         start=freqset[S[0]][1]+1
#         end=freqset[S[-1]][1]+1
#         offset=0
#         for j in range(start,end):
#             flag=True
#             for k in keys:
#                 if freqset[k][0]<j and freqset[k][1]>=j:
#                     flag=False
#                     break
#             if flag:
#                 result.append(j-offset)
#                 offset=j
#         result.append(len(S)-offset)
#         return result

class Solution:
    def partitionLabels(self, S: str) -> List[int]:
        freqset={}
        result=[]
        for i in range(len(S)):
            if S[i] not in freqset.keys():
                freqset[S[i]]=[i,i]
            else:
                freqset[S[i]][1]=i
        offset=0
        start=0
        print(freqset)
        for i in range(len(S)):
            if offset<freqset[S[i]][1]:
                offset=freqset[S[i]][1]
            if i==offset:
                result.append(offset-start)
                start=offset
        # result.append(len(S)-offset)
        result[0]+=1
        return result